#include "widget.h"
#include "ui_widget.h"
#include <QRegularExpressionValidator>
#include <QMessageBox>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->lineEdit->setText("hello LineEdit");

    ui->lineEdit_2->setReadOnly(true);
    ui->lineEdit_2->setText("hello LineEdit");

    ui->lineEdit_3->setText("hello LineEdir");
    ui->lineEdit_3->setEchoMode(QLineEdit::Password);

    ui->lineEdit_4->setText("hello LineEdir");
    ui->lineEdit_4->setEchoMode(QLineEdit::Password);

    QRegularExpression regx("\\w[-\\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14}");
    QValidator *validator = new QRegularExpressionValidator(regx, ui->lineEdit_5);
    ui->lineEdit_5->setValidator(validator);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_lineEdit_rex_returnPressed()
{
    qDebug() << "on_lineEdit_rex_returnPressed";
}

void Widget::on_lineEdit_rex_inputRejected()
{
    qDebug() << "on_lineEdit_rex_inputRejected";
}

void Widget::on_cc_clicked()
{
    const QValidator *v = ui->lineEdit_5->validator();
    int pos = 0;

    QString text = ui->lineEdit_5->text();
    if (v->validate(text, pos) != QValidator::Acceptable)
    {
        ui->lineEdit_5->setText(QString::fromLocal8Bit("邮箱格式不正确"));
    }
    else
    {
        QMessageBox::information(this, u8"标题", u8"邮箱格式正确");
    }
}
